package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantgapService;
import com.youi.entity.Merchantbusiness;
import com.youi.entity.Merchantgap;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 药品经营许可证控制层
* @author Administrator
*/
@Controller
public class MerchantgapController  extends HttpRequestManage{

		@Autowired
		private MerchantgapService merchantgapService;

		/**
		 * I-69
		 * 添加或编辑药品经营许可证
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantgap")
		public String addOrEditMerchantgap(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);			
			Merchantgap merchantgap=merchantgapService.getByParam(prams);
			if (merchantgap==null) {
				merchantgap=new Merchantgap();
				merchantgap.setMerchantId(id);
			}			
			String cardID=optString("cardID",request);
			if (cardID!=null){
				merchantgap.setCardID(cardID);
			}
			String address=optString("address",request);
			if (address!=null){
				merchantgap.setAddress(address);
			}
			String businessScope=optString("businessScope",request);
			if (businessScope!=null){
				merchantgap.setBusinessScope(businessScope);
			}
			String certificate=optString("certificate",request);
			if (certificate!=null){
				merchantgap.setCertificate(certificate);
			}
			merchantgap.setGmtModify(new Date());
			merchantgapService.saveOrUpdate(merchantgap);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		

		/**
		 * I-70
		 * 查询药品经营许可证
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantgapById")
		public String getMerchantgapById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);			
			Merchantgap merchantgap=merchantgapService.getByParam(prams);
			if (merchantgap==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantgap);//jsonObject	json对象
		}
		
}
